/*     */ package com.zimbra.cs.account.ldap.upgrade;
/*     */ 
/*     */ import com.zimbra.common.service.ServiceException;
/*     */ import com.zimbra.cs.account.ldap.LdapDIT;
/*     */ import com.zimbra.cs.account.ldap.LdapProv;
/*     */ import com.zimbra.cs.ldap.IAttributes;
/*     */ import com.zimbra.cs.ldap.LdapClient;
/*     */ import com.zimbra.cs.ldap.LdapServerType;
/*     */ import com.zimbra.cs.ldap.LdapUsage;
/*     */ import com.zimbra.cs.ldap.SearchLdapOptions.SearchLdapVisitor;
/*     */ import com.zimbra.cs.ldap.ZLdapContext;
/*     */ import com.zimbra.cs.ldap.ZLdapFilter;
/*     */ import com.zimbra.cs.ldap.ZLdapFilterFactory;
/*     */ import com.zimbra.cs.ldap.ZMutableEntry;
/*     */ import java.util.Map;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class BUG_50465
/*     */   extends UpgradeOp
/*     */ {
/*  36 */   private static String ATTR_SPREADSHEET = "zimbraFeatureBriefcaseSpreadsheetEnabled";
/*  37 */   private static String ATTR_SLIDES = "zimbraFeatureBriefcaseSlidesEnabled";
/*  38 */   private static String ATTR_NOTEBOOK = "zimbraFeatureNotebookEnabled";
/*     */   
/*     */   void doUpgrade() throws ServiceException
/*     */   {
/*  42 */     ZLdapContext zlc = LdapClient.getContext(LdapServerType.MASTER, LdapUsage.UPGRADE);
/*     */     try {
/*  44 */       doCos(zlc);
/*  45 */       doAccount(zlc);
/*     */     } finally {
/*  47 */       LdapClient.closeContext(zlc);
/*     */     }
/*     */   }
/*     */   
/*     */   private static class Bug50465Visitor extends SearchLdapOptions.SearchLdapVisitor {
/*     */     private UpgradeOp upgradeOp;
/*     */     private ZLdapContext modZlc;
/*     */     
/*     */     private Bug50465Visitor(UpgradeOp upgradeOp, ZLdapContext modZlc) {
/*  56 */       this.upgradeOp = upgradeOp;
/*  57 */       this.modZlc = modZlc;
/*     */     }
/*     */     
/*     */     public void visit(String dn, Map<String, Object> attrs, IAttributes ldapAttrs)
/*     */     {
/*  62 */       ZMutableEntry entry = LdapClient.createMutableEntry();
/*     */       try
/*     */       {
/*  65 */         if (ldapAttrs.getAttrString(BUG_50465.ATTR_SPREADSHEET) != null) {
/*  66 */           entry.setAttr(BUG_50465.ATTR_SPREADSHEET, "FALSE");
/*     */         }
/*  68 */         if (ldapAttrs.getAttrString(BUG_50465.ATTR_SLIDES) != null) {
/*  69 */           entry.setAttr(BUG_50465.ATTR_SLIDES, "FALSE");
/*     */         }
/*  71 */         if (ldapAttrs.getAttrString(BUG_50465.ATTR_NOTEBOOK) != null) {
/*  72 */           entry.setAttr(BUG_50465.ATTR_NOTEBOOK, "FALSE");
/*     */         }
/*  74 */         this.upgradeOp.printer.println("Modifying " + dn);
/*  75 */         this.upgradeOp.replaceAttrs(this.modZlc, dn, entry);
/*     */       }
/*     */       catch (ServiceException e)
/*     */       {
/*  79 */         this.upgradeOp.printer.println("Caught ServiceException while modifying " + dn);
/*  80 */         this.upgradeOp.printer.printStackTrace(e);
/*     */       }
/*     */     }
/*     */   }
/*     */   
/*     */   private void upgrade(ZLdapContext modZlc, String[] bases, String query) {
/*  86 */     SearchLdapOptions.SearchLdapVisitor visitor = new Bug50465Visitor(this, modZlc, null);
/*     */     
/*  88 */     String[] attrs = { ATTR_SPREADSHEET, ATTR_SLIDES, ATTR_NOTEBOOK };
/*     */     
/*  90 */     for (String base : bases) {
/*     */       try {
/*  92 */         this.prov.searchLdapOnMaster(base, query, attrs, visitor);
/*     */       }
/*     */       catch (ServiceException e) {
/*  95 */         this.printer.println("Caught ServiceException while searching " + query + " under base " + base);
/*  96 */         this.printer.printStackTrace(e);
/*     */       }
/*     */     }
/*     */   }
/*     */   
/*     */   private String query() {
/* 102 */     return "(|(" + ATTR_SPREADSHEET + "=" + "TRUE" + ")" + "(" + ATTR_SLIDES + "=" + "TRUE" + ")" + "(" + ATTR_NOTEBOOK + "=" + "TRUE" + ")" + ")";
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */   private void doCos(ZLdapContext modZlc)
/*     */   {
/* 109 */     String[] bases = this.prov.getDIT().getSearchBases(32);
/* 110 */     String query = "(&" + ZLdapFilterFactory.getInstance().allCoses().toFilterString() + query() + ")";
/* 111 */     upgrade(modZlc, bases, query);
/*     */   }
/*     */   
/*     */   private void doAccount(ZLdapContext modZlc) {
/* 115 */     String[] bases = this.prov.getDIT().getSearchBases(1);
/* 116 */     String query = "(&" + ZLdapFilterFactory.getInstance().allAccounts().toFilterString() + query() + ")";
/* 117 */     upgrade(modZlc, bases, query);
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/account/ldap/upgrade/BUG_50465.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */